package com.bd08.flink.demo.jing.table


import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.table.api.Expressions.{$, row}
import org.apache.flink.table.api.bridge.scala.StreamTableEnvironment
import org.apache.flink.table.api.{DataTypes, EnvironmentSettings, TableEnvironment}


object TableDemo  extends App {


  //创建 table 执行上下文
  val settings = EnvironmentSettings.inStreamingMode
  val tenv = TableEnvironment.create(settings)


  //创建 流 到 table 的执行上下午
  val env = StreamExecutionEnvironment.getExecutionEnvironment
  val stenv = StreamTableEnvironment.create(env)


   //获取数据
   //(("Jason","9","2010-1-1"),("Tom","9","2010-1-1"))
  val t1=tenv.fromValues(
    DataTypes.ROW(
      DataTypes.FIELD("name", DataTypes.STRING().notNull())
      ,
      DataTypes.FIELD("age", DataTypes.STRING().notNull())
      ,
      DataTypes.FIELD("birth", DataTypes.STRING().notNull())

  ),row("Jason","9","2010-1-1"),row("Tom","9","2010-1-1"))
  t1.printSchema()
  t1.select($("*")).execute().print()

  tenv.createTemporaryView("person",t1)

  tenv.executeSql("select * from person").print()





}
